<html>
<head>
<meta charset="UTF-8">
<title>广播测试</title>
<script type="text/javascript" src="/js/jquery.js"></script>

</head>
<body>
	你的id:<span id="userID" data-id="${userinfo.id}">${userinfo.id}</span><button onclick="connect()">连接</button><br>
	输入你的内容:<input type="text" id="writeMsg"><button onclick="sendMsg()">发送</button>
	<script type="text/javascript">
	
		var ws=null;
		
		function connect(){
			if("WebSocket" in window){
				ws=new WebSocket("ws://localhost:8080/socket/"+$("#userID").attr("data-id"));
			}else if("MozWebSocket" in window){
				ws=new MozWebSocket("ws://localhost:8080/socket/"+$("#userID").attr("data-id"));
			}else{
				alert("该浏览器不支持websocket");
			}
			
			//接收服务器发来的消息
			ws.onmessage=function(evt){
				//console.log(evt);
				alert(evt.data);
			}
			
			ws.onclose=function(evt){
				alert("连接关闭");
			}
			
			ws.onopen=function(evt){
				alert("连接成功");
			}
		}
		
		function sendMsg(){
			ws.send($("#writeMsg").val());
		}
	</script>
</body>
</html>